#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

// 75.48 %
class Solution
{
  public:
	string frequencySort(string s)
	{
		map<char, int> tMap;
		for (int i = 0; i < s.size(); i++)
		{
			tMap[s[i]]++;
		}
		vector<pair<char, int>> tVector;

		for (map<char, int>::iterator curr = tMap.begin(); curr != tMap.end(); curr++)
			tVector.push_back(make_pair(curr->first, curr->second));

		sort(tVector.begin(), tVector.end(), cmp);

		string re = "";

		for (int i = 0; i < tVector.size(); i++)
		{
			for (int j = 0; j < tVector[i].second; j++)
			{
				re += tVector[i].first;
			}
		}

		return re;
	}
	static int cmp(const pair<char, int> &x, const pair<char, int> &y)
	{
		return x.second > y.second;
	}
};

int main()
{
	string s = "Aabb";
	cout << Solution().frequencySort(s) << endl;
	return 0;
}
